import becker.robots.*;
public class superRobot extends Robot{

	public superRobot(City aCity, int aStreet, int anAvenue,
			Direction aDirection) {
		super(aCity, aStreet, anAvenue, aDirection);
	}

	public void move(int i){
		for (int x = 0; x < i; x++){
			move();
		}
	}

	public void turnLeft(int i){
		for (int x =  0; x < i; x++){
			turnLeft();
		}
	}

	public void turnRight(){
		turnLeft(3);
	}

	public void changeDir(Direction dir){
		while (super.getDirection()!= dir) {
			super.turnLeft();
		}
	}

	public void checkPossible(int[] possible){
		changeDir(Direction.NORTH);
		if (frontIsClear()) {
			possible[0] = 1;
		} else {
			possible[0] = 0;
		}
		changeDir(Direction.WEST);
		if (frontIsClear()) {
			possible[3] = 1;
		} else {
			possible[3] = 0;
		}
		changeDir(Direction.SOUTH);
		if (frontIsClear()) {
			possible[2] = 1;
		} else {
			possible[2] = 0;
		}
		changeDir(Direction.EAST);
		if (frontIsClear()) {
			possible[1] = 1;
		} else {
			possible[1] = 0;
		}
	}

	public int returnPossible(boolean[][] a) {
		int x = 0;
		if (getStreet() != 0){
			changeDir(Direction.NORTH);
			if (frontIsClear() && (a[getAvenue()][getStreet()-1])) {
				x++;
			}
		}
		if (getAvenue() != 0){
			changeDir(Direction.WEST);
			if (frontIsClear() && (a[getAvenue()-1][getStreet()])) {
				x++;
			}
		}
		if (getStreet() != 9){
			changeDir(Direction.SOUTH);
			if (frontIsClear() && (a[getAvenue()][getStreet()+1])) {
				x++;
			}
		}
		if (getAvenue() != 9) {
			changeDir(Direction.EAST);
			if (frontIsClear() && (a[getAvenue()+1][getStreet()])) {
				x++;
			}
		}
		return x;
	}

	public int setY(int y) {
		if (getDirection() == Direction.EAST){
			y = getStreet();
		} else if (getDirection() == Direction.SOUTH){
			y = getStreet() + 1;
		} else if (getDirection() == Direction.NORTH){
			y = getStreet() - 1;
		} else if (getDirection() == Direction.WEST){
			y = getStreet();
		}
		return y;
	}

	public int setX(int x) {
		if (getDirection() == Direction.EAST){
			x = getAvenue() + 1;
		} else if (getDirection() == Direction.SOUTH){
			x = getAvenue();
		} else if (getDirection() == Direction.NORTH){
			x = getAvenue();
		} else if (getDirection() == Direction.WEST){
			x = getAvenue() - 1;
		}
		return x;
	}

	public int getPreviousX() {
		int x = 0;
		if (getStreet() != 0){
			changeDir(Direction.NORTH);
			x = getAvenue();
		}
		if (getAvenue() != 0){
			changeDir(Direction.WEST);
			x = getAvenue() + 1;
		}
		if (getStreet() != 9){
			changeDir(Direction.SOUTH);
			x = getAvenue();		
		}
		if (getAvenue() != 9) {
			changeDir(Direction.EAST);
			x = getAvenue() - 1;		
		}
		
		return x;
	}
	
	public int getPreviousY() {
		int y = 0;
		if (getStreet() != 0){
			changeDir(Direction.NORTH);
			y = getStreet() + 1;
		}
		if (getAvenue() != 0){
			changeDir(Direction.WEST);
			y = getStreet();
		}
		if (getStreet() != 9){
			changeDir(Direction.SOUTH);
			y = getStreet() - 1;			
		}
		if (getAvenue() != 9) {
			changeDir(Direction.EAST);
			y = getStreet();			
		}
		
		return y;
	}
}
